<template>
    <div>
        <h2 ref="title">哈哈</h2>
        <NavBar ref="navBar"></NavBar>
        <button @click="btnClick">获取navBar信息</button>
    </div>
</template>

<script>
import NavBar from './NavBar.vue'
export default {
    components: { NavBar },
    methods: {
        btnClick() {
            console.log(this.$refs.title);  //获取元素<h2></h2>
            console.log(this.$refs.navBar); //获取组件实例的代理
            console.log(this.$refs.navBar.msg); //获取组件的信息
            this.$refs.navBar.sayHello()    //执行组件的方法
        }
    },
}
</script>

<style lang="scss" scoped>
</style>